package com.javagroup.chessonline;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import java.awt.Image;

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ChessDemo {

	private JFrame frame;
	private JFrame pawnFrame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ChessDemo window = new ChessDemo();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 * 
	 * @throws IOException
	 */
	public ChessDemo() throws IOException {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 * 
	 * @throws IOException
	 */
	private void initialize() throws IOException {
		frame = new JFrame();

		frame.setBounds(0, 50, 600, 600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new BorderLayout());

		// code create board
		Image blackBlock = ImageIO.read(new File(
				"Resources/Images/black-piece.png"));
		Image whiteBlock = ImageIO.read(new File(
				"Resources/Images/white-piece.png"));

		Board board = new Board(whiteBlock, blackBlock);

		pawnFrame = new JFrame();
		pawnFrame.setBounds(0, 50, 600, 600);
		pawnFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.getContentPane().add(board, BorderLayout.CENTER);
		// add panel test
		JPanel testPanel = new JPanel();
		testPanel.setPreferredSize(new Dimension(110, 200));
		testPanel.setSize(500, 500);
		testPanel.setLayout(null);

		JButton btnTest = new JButton("TEST");
		btnTest.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				pawnFrame.setVisible(true);
			}
		});
		btnTest.setBounds(10, 39, 89, 23);
		testPanel.add(btnTest);
		JLabel testLbl = new JLabel();
		testLbl.setPreferredSize(new Dimension(110, 110));
		testLbl.setBounds(10, 11, 86, 14);
		testLbl.setText("Room Information");
		testPanel.add(testLbl);
		frame.getContentPane().add(testPanel, BorderLayout.LINE_START);
	}

}
